package collection;

import string.Point;

import java.util.ArrayList;
import java.util.Collection;

/**
 * [
 * Point{x=200, y=300},
 * Point{x=200, y=300}
 * ]
 */
public class CollectionDemo2 {
    public static void main(String[] args) {
        Point p1 = new Point(200, 300);
        Point p2 = new Point(200, 300);
        System.out.println(p1.equals(p2));// true

        Collection c1 = new ArrayList();
        c1.add(p1);
        c1.add(p2);
        System.out.println(c1);
        Point p3 = new Point(300, 300);
        c1.add(p3);
        System.out.println(c1);
         /*
          boolean contains(Object o)
          判断当前集合是否包含给定元素o
          判断依据是给定元素与当前集合元素是否存在equals()为true的情况
         */
        boolean result = c1.contains(p1);
        System.out.println(result);
 /*
          boolean contains(Object o)
          判断当前集合是否包含给定元素o
          判断依据是给定元素与当前集合元素是否存在equals()为true的情况
         */
        Point p4 = new Point(500, 300);
        System.out.println(c1.contains(p4));
/*
          boolean remove(Object o):---------一般都不接收boolean结果
          从当前集合中删除与给定元素o的equals()比较为true的元素
          若存在重复元素则只删除第1次匹配的
         */
       boolean result2= c1.remove(p4);
        System.out.println(result2);
        Point p5 = new Point(200, 300);

        result2 = c1.remove(p5);//能移除，因为有 200  300 的点。
        System.out.println(result2);
        System.out.println(c1);

    }
}
